package com.jt.controller;

import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.service.ItemService;
import com.jt.vo.EasyUITable;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/item")
public class ItemController {

	@Autowired
	private ItemService itemService;

	/**
	 * 业务需求: 商品信息的分页查询
	 * url地址:
	 */
	@RequestMapping("/query")
	public EasyUITable findItemByPage(Integer page, Integer rows) {

		return itemService.findItemByPage(page, rows);
	}

	/**
	 * 业务需求: 完成商品入库操作,返回系统vo对象
	 *
	 * @param item
	 * @return
	 */
	@RequestMapping("/save")
	public SysResult saveItem(Item item, ItemDesc itemDesc) {
		itemService.saveItem(item, itemDesc);
		return SysResult.success();
	}

	/**
	 * 删除商品信息
	 *
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delete")
	public SysResult deleteItem(Long... ids) {
		itemService.deleteItem(ids);
		return SysResult.success();
	}

	/**
	 * 更新商品信息
	 *
	 * @param item
	 * @return
	 */
	@RequestMapping("/update")
	public SysResult updateItem(Item item, ItemDesc itemDesc) {
		itemService.updateItem(item, itemDesc);
		return SysResult.success();
	}

	/**
	 * 下架/上架
	 *
	 * @param ids
	 * @return
	 */
	@RequestMapping("/updateStatus/{status}")
	public SysResult updateStatus(@PathVariable Integer status, Long... ids) {
		itemService.updateStatus(status, ids);
		return SysResult.success();
	}

	///item/query/item/desc/
	@RequestMapping("query/item/desc/{id}")
	public SysResult findItemDescById(@PathVariable Long id) {
		return SysResult.success(itemService.findItemDescById(id));
	}
}
